package net.minecraft.src;

public class InventoryTehVillager extends InventoryBasic {

	private static final int inventorySize = 16;
	public int currentSlot = 0;
	public NBTTagCompound saveTags;
	
	public InventoryTehVillager(EntityTehVillager ent) {
		super(String.format("villager_inv_%d", ent.hashCode()), inventorySize);
	}
	
	public ItemStack getCurrentItem() {
		try {
			return getStackInSlot(currentSlot);
		} catch (NullPointerException ex) {
			return null;
		}
	}
	
	public boolean hasItem(Item item) {
		boolean found = false;
		for (int i=0; i < inventorySize; i++) {
			if (getStackInSlot(i).getItem() == item)
				return true;
		}
		return false;
	}
	
	public NBTTagCompound writeToNBT(NBTTagCompound saveData) {
		for (int i=0; i < inventorySize; i++) {
			if (getStackInSlot(i) != null) {
				NBTTagCompound slotTags = new NBTTagCompound();
				getStackInSlot(i).writeToNBT(slotTags);
				saveData.setCompoundTag(String.valueOf(i), slotTags);
			}
		}
		return saveData;
	}
	
	public void readFromNBT(NBTTagCompound saveData) {
		for (int i=0; i < inventorySize; i++) {
			NBTTagCompound slotTags = saveData.getCompoundTag(String.valueOf(i));
			if (!slotTags.getTags().isEmpty()) {
				int itemID = slotTags.getShort("id");
				int count = slotTags.getByte("Count");
				int damage = slotTags.getShort("Damage");
				setInventorySlotContents(i, new ItemStack(itemID, count, damage));
			}
		}
	}
	

}
